home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 129_01.zip / EXPAND.C < prev    next >
Text File  |  1993-06-01  |  5KB  |  154 lines

  1. #include <210ctdl.h>
  2. /*****************************************************************************/
  3. /*                expand.c                     */
  4. /*                                         */
  5. /*            Expands a msg file.  V.1.2                 */
  6. /*****************************************************************************/
  7.  
  8. /*****************************************************************************/
  9. /*                history                      */
  10. /*                                         */
  11. /* 84Dec09 HAW    Now merely expands a file, rather than copying & expanding.  */
  12. /* 84Jun22 HAW    Version 1.1 created -- handles any file expansion.         */
  13. /* 84Jun19 HAW    Created.                             */
  14. /*****************************************************************************/
  15.  
  16. /*****************************************************************************/
  17. /*                contents                     */
  18. /*                                         */
  19. /*    copy_remainder()    Copies remainder of split msg into file      */
  20. /*    first_part()        Remembers remainder of split msg         */
  21. /*    main()            Main controller for this program         */
  22. /*****************************************************************************/
  23.  
  24. /*****************************************************************************/
  25. /*                External files                     */
  26. /*                                         */
  27. /*                210modem.c                     */
  28. /*                210rooma.c                     */
  29. /*                210roomb.c                     */
  30. /*                210log.c                     */
  31. /*                210modem.c                     */
  32. /*                210misc.c                     */
  33. /*                210msg.c                     */
  34. /*                                         */
  35. /*    The files cited above must be linked in -- additionally, this file   */
  36. /*    must be compiled using the same -e address as Citadel.             */
  37. /*****************************************************************************/
  38.  
  39. /*****************************************************************************/
  40. /*    copy_remainder()    copies the remainder of the split msg onto   */
  41. /*                the "end" of the file                 */
  42. /*****************************************************************************/
  43. unsigned copy_remainder(offset, nfd)
  44. unsigned offset;
  45. int nfd;
  46. {
  47.     char *beg;
  48.     int  count, i;
  49.  
  50.     beg = codend();
  51.     count = 0;
  52.     printf("Transfer %d sectors to cover split msg\n",
  53.           (offset) ? offset / SECTSIZE + 1 : 0);
  54.     while (1) {
  55.     if (offset < SECTSIZE) break;
  56.     crypte(beg + SECTSIZE * count, SECTSIZE, 0);
  57.     if (write(nfd, beg + SECTSIZE * count, 1) != 1)
  58.         exit(printf("\nError on write: %s", errmsg(errno())));
  59.     count++;
  60.     offset -= SECTSIZE;
  61.     }
  62.     if (offset == 0) return count;
  63.     for (i = 0; beg[SECTSIZE * count + i] != 255; i++) ;
  64.     for (i++; i < SECTSIZE; i++)
  65.     beg[SECTSIZE * count + i] = 0;
  66.     crypte(beg + SECTSIZE * count, SECTSIZE, 0);
  67.     if (write(nfd, beg + SECTSIZE * count, 1) != 1)
  68.     exit(printf("\nError on write: %s", errmsg(errno())));
  69.     return count + 1;
  70. }
  71.  
  72. /*****************************************************************************/
  73. /*    first_part()    remembers remainder of first msg             */
  74. /*****************************************************************************/
  75. unsigned first_part(startat)
  76. char *startat;
  77. {
  78.     int  offset, i;
  79.     char done, buf[SECTSIZE];
  80.  
  81.     offset = 0;
  82.     done   = FALSE;
  83.     do {
  84.     if (read(msgfl, buf, 1) != 1)
  85.         exit(printf("\nError on read: %s", errmsg(errno())));
  86.     crypte(buf, SECTSIZE, 0);
  87.     i = 0;
  88.     while (buf[i] != 255 && i < SECTSIZE)
  89.         startat[offset++] = buf[i++];
  90.     done = !(i == SECTSIZE);
  91.     } while (!done);
  92.     seek(msgfl, 0, 0);
  93.     return offset;
  94. }
  95.  
  96. /*****************************************************************************/
  97. /*    main()    the main controller                         */
  98. /*****************************************************************************/
  99. main()
  100. {
  101.     char     *msgFile, temp[BUFSIZ];
  102.     int      s, i, offset, setup();
  103.     char     *buf;
  104.     unsigned bufs, bufad, oldsize, fudge;
  105.  
  106.     printf("%u buffer space\n", externs() - codend());
  107.     printf("Citadel Message expansion program V1.2.\n");
  108.     printf("HAVE YOU BACKED UP THE CTDLMSG.SYS FILE YET(Y/N)? ");
  109.     if (toUpper(getCh()) != 'Y') {
  110.     printf("\nTHEN DO SO, IDIOT!");
  111.     exit();
  112.     }
  113.     printf("\n\nOne moment, please...\n");
  114.     if (readSysTab()) {
  115.     msgFile     = "a:ctdlmsg.sys";
  116.     *msgFile   += msgDisk;
  117.     openFile(msgFile, &msgfl);
  118.  
  119.     haveCarrier = FALSE;
  120.     onConsole   = TRUE;
  121.     whichIO     = CONSOLE;
  122.     oldsize     = maxMSector;
  123.  
  124.     printf("\nOld size was %dK", maxMSector / 8);
  125.     maxMSector = getNumber("\nNew size (in decimal!)", maxMSector/8, 65535);
  126.     maxMSector *= 8;
  127.     printf("\nThank you.  Working...");
  128.     bufad = buf = codend() + (offset = first_part(codend()));
  129.     bufs = externs() - 1 - bufad;
  130.     if (bufs < SECTSIZE)
  131.         exit(printf("Not even 128 bytes are available!"));
  132.  
  133.     writeSysTab();        /* Restore again, don't have to reconfigure */
  134.  
  135.     seek(msgfl, oldsize, 0);    /* Get to EOF */
  136.     while (read(msgfl, temp, 1) == 1) printf("Looping\n");
  137.     fudge = copy_remainder(offset, msgfl);
  138.     for (i = 0; i < SECTSIZE; i++) buf[i] = 0;
  139.     crypte(buf, SECTSIZE, 0);
  140.     i = maxMSector - oldsize - fudge;
  141.     printf("And now %7d sectors left to initialize\n", i);
  142.     for (; i; i--) {
  143.         printf("%7d\r", i);
  144.         if ((s = write(msgfl, buf, 1)) != 1)
  145.         exit(printf("\nError on write: %s", errmsg(errno())));
  146.     }
  147.     close(msgfl);
  148.     printf("\nFinished.  Don't need to reconfigure!  But don't forget");
  149.     printf(" to change CTDLCNFG.SYS.");
  150.     }
  151. }
  152. ctor;
  153.  
  154.     printf("\nOld size was %dK",